<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/27
 * Time: 18:14
 */

namespace app\index\model;
use think\Model;
use think\Db;
class CardModel extends Model{
    // 确定链接表名
    protected $table = 'snake_card';
    public function getLists($param){
        $pageNo=1;$pageSize=10;
        if(isset($param['pageNo']) && $param['pageNo']!='' && $param['pageNo']>1) $pageNo=intval($param['pageNo']);
        if(isset($param['pageSize']) && $param['pageSize']!='' && $param['pageSize']>0) $pageSize=intval($param['pageSize']);
        return $this->order('list_order DESC,addtime DESC,id DESC')->limit(($pageNo-1)*$pageSize,$pageSize)->select();
    }
    public function getCardProgress($param){
        $pageNo=1;$pageSize=10;
        if(isset($param['pageNo']) && $param['pageNo']!='' && $param['pageNo']>1) $pageNo=intval($param['pageNo']);
        if(isset($param['pageSize']) && $param['pageSize']!='' && $param['pageSize']>0) $pageSize=intval($param['pageSize']);
        $user_id=session('user_id');
        $sql=Db::name('apply')->distinct(true)->field('pid')
            ->where("user_id=$user_id AND type=0")
            ->limit(($pageNo-1)*$pageSize,$pageSize)
            ->order('addtime DESC,order_id DESC')->buildSql();
        return Db::table($sql.' apply')->join('__CARD__ card','apply.pid = card.id')->select();
    }
    public function getOne($id){
        return $this->where(array('id'=>$id))->find();
    }
    public function getLink($id){
        return $this->where(array('id'=>$id))->value('link');
    }
}